// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "MotionSubtitlesLayerBase.h"
#include "NiagaraSystem.h"
#include "MotionSubtitlesNiagaraLayer.generated.h"


UCLASS(ClassGroup=(MotionSubtitles), meta=(BlueprintSpawnableComponent))
class MOTIONSUBTITLES_API UMotionSubtitlesNiagaraLayer : public UMotionSubtitlesLayerBase
{
	GENERATED_BODY()

public:

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=MotionSubtitles)
	TObjectPtr<UNiagaraSystem> FXAsset;

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=MotionSubtitles)
	TObjectPtr<UMaterialInterface> TextMaterialOverride;

	UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category=MotionSubtitles)
	TObjectPtr<UTextureRenderTarget2D> EmitterMask;

	UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category=MotionSubtitles)
	TObjectPtr<UNiagaraComponent> NiagaraComponent;

	UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category=MotionSubtitles)
	TObjectPtr<USceneCaptureComponent2D> EmitterMaskCaptureComponent2D;

	UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category=MotionSubtitles)
	TArray<TObjectPtr<UStaticMeshComponent>> TextPlanes;

	TArray<FVector> TextOriginLocations;
	TArray<FVector> TextOriginScales;

public:
	UMotionSubtitlesNiagaraLayer();

	virtual void Init(const FUint32Vector2& ViewSize) override;

	virtual void Show(const FSubtitleParams& Params) override;

	virtual void ShowDeferred(const FSubtitleParams& Params) override;

	virtual void Hide() override;

	virtual void Exit() override;

public:
	virtual void DoScale(const EAnimTarget AnimTarget, const int32 ElementId, const float Value) override;
	virtual void DoTranslate(const EAnimTarget AnimTarget, const int32 ElementId, const FVector Value) override;
	virtual void DoFade(const EAnimTarget AnimTarget, const int32 ElementId,const float Value) override;
	virtual void DoDissolve(const EAnimTarget AnimTarget, const int32 ElementId,const float Value) override;
	virtual void CaptureStatus() override;
	virtual int32 ElementCount() override;

private:
	bool DuplicateTextMeshes(TArray<TObjectPtr<UStaticMeshComponent>>& TextMeshes);
	bool ReplaceTextMaterials(TArray<TObjectPtr<UStaticMeshComponent>>& TextMeshes);
};
